$(function () {
  var body = document.getElementsByTagName('body')[0];
  if (body.id === 'aboutBody') {
    /*初始化视频*/
    var player;
    var honorPlayer;
    var memberPlayer;
    var $startPlay = $('#startPlay');                    // 公司介绍开始视频按钮
    var $memberStartPlay = $('#memberStartPlay');        // 成员介绍开始视频按钮

    var $companyVideo = $('.company-video');             // 公司介绍视频盒子
    var $memberVideo = $('.member-video');               // 成员风采视频盒子

    var $initVideoImg = $('.initVideoImg');              // 初始化背景图片
    var $initMemberImg = $('.initMemberImg');            // 初始化背景图片

    var $childMenuList = $('#childMenu li');             // 二级导航按钮
    var $liA = $('#childMenu li a');                     // 二级导航按钮的a标签
    var $headImgList = $('.headImgBox .headImg');
    var honorNewsLists = $('.honor-news .honor-tit');    // 荣誉资质新闻
    var memberNewsLists = $('.member-news .honor-tit');  // 荣誉资质新闻
    var everYearLi = $('.everYear li');                  // 发展历程的时间轴
    var thisYear = $('.thisYear')[0];                    // 当前年份

    var $memberSwiper = $('.MenberSwiper');
    var $leader = $('.leader');
    /*点击视频播放与暂停*/
    $companyVideo.on('click', function () {
      playVideoComon(player, $initVideoImg, $startPlay);
    });

    /*点击员工风采视频播放与暂停*/
    $memberVideo.on('click', function () {
      playVideoComon(memberPlayer, $initMemberImg, $memberStartPlay);
    });

    /*公共播放的方法*/
    function playVideoComon(videoPlayer, initBg, videoStartBtn) {   //视频id，初始背景图片，开始按钮
      videoPlayer.play();
      $(initBg).hide();
      if (videoStartBtn.hasClass('startPlay')) {
        videoStartBtn.hide().removeClass('startPlay');
        videoPlayer.play();
      } else {
        videoStartBtn.show().addClass('startPlay');
        videoPlayer.pause();
      }
    }

    var videoInit = function () {
      var u = navigator.userAgent;
      var options = {};
      player = videojs('my-player', options);
      memberPlayer = videojs('member-player', options);
      // 加载完成自动播放且没声音
      player.on('loadeddata', function () {
        DOM.$video.addClass('visible');
        player.volume(0);
      });
    };
    videoInit();
    // 给swiper绑定change插件
    mySwiper.on('slideChange', function () {

        // 非移动端才执行本段代码
        // 切换一屏就停止播放视频
        player.pause();
        $startPlay.show();
        $startPlay.addClass('startPlay');
        memberPlayer.pause();
        $memberStartPlay.show();
        $memberStartPlay.addClass('startPlay');


      // 页面切换后执行
      var $menuName = $('#menuName');
      // 根据不同的index，更换不同的menu的名字
      $menuName.html($liA[this.activeIndex].text);
    });

    /*二级导航滚屏*/
    for (var i = 0; i < $childMenuList.length; i++) {
      $childMenuList[i].index = i;
      $childMenuList[i].onclick = function () {
        mySwiper.slideTo(this.index, 1000, false);//切换到第一个slide，速度为1秒
      }
    }

    /*成员风采轮播图*/
    var menberSwiper = new Swiper('.MenberSwiper', {
      direction: 'horizontal',
      loop: true,
      //切换效果
      effect: 'fade',
      // 响应鼠标滚轮
      mousewheel: false,
      // 将宽和高取整，防止某些情况下边界模糊
      roundLengths: true,
      lazy: true,
    });

    /*荣誉资质*/
    var honorSwiper = new Swiper('.honorSwiper',{
      direction: 'horizontal',
      loop: true,
      // 将宽和高取整，防止某些情况下边界模糊
      roundLengths: true,
      spaceBetween:30,
      lazy: true,
      slidesPerView : 'auto',
      slideToClickedSlide:true,
      navigation:{
        prevEl:'.button-prev',
        nextEl:'.button-next'
      },
      centeredSlides:false,
      touchRatio:0.2,
      slideToClickedSlide:true,
    });

    /*员工风采*/
    var travelSwiper = new Swiper('.travelSwiper',{
      direction: 'horizontal',
      loop: false,
      // 将宽和高取整，防止某些情况下边界模糊
      roundLengths: true,
      spaceBetween:10,
      lazy: true,
      slidesPerView : 'auto',
      navigation:{
        nextEl:'.swiper-button-next',
        prevEl:'.swiper-button-prev'
      },
      centeredSlides:true,
      touchRatio:0.2,
      slideToClickedSlide:true,
    });

    var bigSwiper = new Swiper('.scaleSwiper',{
      spaceBetween:10,
    });
    travelSwiper.controller.control = bigSwiper;
    bigSwiper.controller.control = travelSwiper;

    /*悬浮去除mask*/
    for (var i = 0; i < $headImgList.length; i++) {
      $($leader[i]).hide();
      $headImgList[i].index = i;
      $headImgList[i].onmouseover = function () {
        var index = $(this).attr('data-id');
        $(this.children[0]).removeClass("mask");
        for (var j = 0; j < $leader.length; j++) {
          if ($($leader[j]).attr('data-id') == index) {
            $("#bossWord").hide();
            $($leader[j]).show();
            return;
          }
        }
      };
      $headImgList[i].onmouseout = function () {
        var index = $(this).attr('data-id');
        $(this.children[0]).addClass("mask");
        for (var j = 0; j < $leader.length; j++) {
          if ($($leader[j]).attr('data-id') == index) {
            $($leader[j]).hide();
            $("#bossWord").show();
            return;
          }
        }
      }
    }

    /*点击荣誉资质的标题，展开内容*/
    clickHonorWay(honorNewsLists);
    /*点击成员风采标题，展开内容*/
    clickWay(memberNewsLists, $memberSwiper);

    /*点击展开的方法*/
    function clickHonorWay(newsList) {
      $(newsList[0].children[0]).slideDown();
      $(newsList[0]).addClass('flagActive');
      for (var i = 0; i < newsList.length; i++) {
        newsList[i].index = i;
        newsList[i].onclick = function () {
          var _this = $(this);
          if (!_this.hasClass('flagActive')) {
            $((_this.siblings('div')).children()).slideUp();
            _this.siblings('div').removeClass('flagActive').removeClass('news-active');
            $(_this.children('div')[0]).slideDown();
            _this.addClass('flagActive').addClass('news-active');
          }
        }
      }
    }


    function clickWay(newsList, swiperList) {
      $(newsList[0].children[0]).slideDown();
      $(newsList[0]).addClass('flagActive');
      $(swiperList[0]).show().siblings('div').hide();
      for (var i = 0; i < newsList.length; i++) {
        newsList[i].index = i;
        newsList[i].onclick = function () {
          var _this = $(this);
          var swiperIndex = this.index;
          $(swiperList[swiperIndex]).show().siblings('div').hide();
          if (!_this.hasClass('flagActive')) {
            $((_this.siblings('div')).children()).slideUp();
            _this.siblings('div').removeClass('flagActive').removeClass('news-active');
            $(_this.children('div')[0]).slideDown();
            _this.addClass('flagActive').addClass('news-active');
          }
        }
      }
    }

    thisYear.onmouseover = function () {
      for (var i = 0; i < everYearLi.length; i++) {
        $($(everYearLi[i]).find('.yearEvent')[0]).slideUp();
        $(everYearLi[i]).removeClass('flagActive');
      }
      if(!$(thisYear).hasClass('flagActive')){
        $($(thisYear).find('.yearEvent')[0]).slideDown();
        $(thisYear).addClass('flagActive');
      }else{
        return;
      }
    }

    /*发展历程的时间轴*/
    for (var i = 0; i < everYearLi.length; i++) {
      $($(everYearLi[i]).find('.yearEvent')[0]).slideUp();
      everYearLi[i].onmouseover = function () {
        $($(thisYear).find('.yearEvent')[0]).slideUp();
        $(thisYear).removeClass('flagActive');
        var _this = $(this);
        if (_this.hasClass('flagActive')) {
       /*  $(_this.find('.yearEvent')[0]).slideUp();
           _this.removeClass('flagActive');
           $($(thisYear).find('.yearEvent')[0]).slideDown();
           $(thisYear).addClass('flagActive');*/
          return;
        } else {
          $(_this.siblings('li').find('.yearEvent')[0]).slideUp();
          $(_this.find('.yearEvent')[0]).slideDown();
          _this.siblings('li').removeClass('flagActive');
          _this.addClass('flagActive');
        }
      }
    }
  }
});
